package com.qiaofang.housewarehouse.stub.feign.client.impl;

import com.qiaofang.common.exception.BusinessException;
import com.qiaofang.housewarehouse.stub.constants.ResponseCode;
import com.qiaofang.housewarehouse.stub.facade.RentalHouseQueryFacade;
import com.qiaofang.housewarehouse.stub.feign.client.RentalHouseQueryClient;
import com.qiaofang.housewarehouse.stub.request.HouseQueryDetailRequest;
import com.qiaofang.housewarehouse.stub.request.RentalHouseQueryRequest;
import com.qiaofang.housewarehouse.stub.response.RentalHouseQueryDetailResponse;
import com.qiaofang.housewarehouse.stub.response.RentalHouseQueryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RentalHouseQueryClientImpl implements RentalHouseQueryClient {

    @Autowired
    private RentalHouseQueryFacade rentalHouseQueryFacade;

    @Override
    public RentalHouseQueryResponse searchRentalHouseList(RentalHouseQueryRequest rentalHouseQueryRequest) {
        RentalHouseQueryResponse response = rentalHouseQueryFacade.searchRentalHouseList(rentalHouseQueryRequest);
        if (ResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            return response;
        } else {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }

    @Override
    public RentalHouseQueryDetailResponse getRentalHouseDetail(HouseQueryDetailRequest rentalHouseQueryDetailRequest) {
        RentalHouseQueryDetailResponse response = rentalHouseQueryFacade.getRentalHouseDetail(rentalHouseQueryDetailRequest);
        if (ResponseCode.RC_SUCCESS.getResponseCode().equals(response.getResponseCode())) {
            return response;
        } else {
            throw new BusinessException(response.getResponseCode(), response.getResponseMessage());
        }
    }
}
